#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
#include <vector>
using ll = int64_t;
#define printf
ll n,ans;
std::vector<ll> a;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin>>n;
    a.resize(n);
    for(ll i=0;i<n;i++)std::cin>>a[i];

    std::sort(a.begin(),a.end());
    a.erase(std::unique(a.begin(),a.end()),a.end());
    n=a.end()-a.begin();
    std::reverse(a.begin(),a.end());

    for(auto i:a){
        printf("%lld ",i);
    }
    printf("\n");
    for(ll k=0;k<n;k++){
        if(a[k]<=ans)break;
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                if(i==j||i==k||j==k)continue;
                if(a[i]+a[j]<a[k])break;
                if(ll nxt=(a[i]+a[j])%a[k];nxt>=ans){
                    ans=nxt;
                }
            }
        }
    }
    out:;
    std::cout<<ans<<"\n";
}